<template>
    <div class="floor1">

        <div class="right">
            <div class="right-1">
                <img :src="PIC_URL + bixue">
            </div>
            <div class="right-2">
                <div v-for="item in bannerArr" :key="item.id" v-if="item.place == 'video'" @click="onClick(item)">
                    <img :src="item.imgUrlClient" style="width: 279px;height: 54px;">
                </div>
            </div>
        </div>


        <div class="content">

            <!--最新文章开始-->
            <div class="content-1">
                <div class="content-1-head">
                    <img :src="PIC_URL + '/experience/images/icon3.png'" style="width: 25px;height: 25px;">
                    <span class="content-1-text">最近更新</span>
                </div>
                <div class="content-1-group">
                    <div class="content-1-cell" v-for="item in recentUpdate" :key="item.id"
                         @click="item.type == 2 ? onVideo(item.recordedVideo) : onArticle(item.article)">
                        <div class="content-1-cell-1">
                            <span class="content-1-cell-text">【{{
                                    item.type == 2 ? '视频' : '文章'
                                }}】</span>{{ item.type == 2 ? item.recordedVideo.subject : item.article.articleTitle }}
                        </div>
                        <div>[{{ (item.type == 2 ? item.recordedVideo.recordStartTime : item.article.publishTime) | formatDate('MM-DD') }}]</div>
                    </div>
                </div>
            </div>
            <!--最新文章结束-->


            <div class="content-2">

                <div class="content-2-title" v-if="zfyObj">
                    {{ zfyObj.channelName }}
                </div>

                <div class="content-2-com" @click="onVideo(zfyObj);" v-if="zfyObj">
                    <div class="video">
                        <img :src="zfyObj.wholeImage" style="width: 100%;height: 100%">
                        <div class="bofang-box">
                            <img class="bofang" :src="PIC_URL + '/experience/bofang.png'"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="left">
            <div class="left-1">

                <div class="left-1-head">
                    <img :src="PIC_URL + '/experience/images/icon1.png'" style="width: 25px;height: 23px;">
                    <span class="left-1-head-text">精选视频</span>
                </div>

                <div class="left-1-con">
                    <el-carousel trigger="click" height="170px" arrow="never" :autoplay="false" @change="onChange">
                        <el-carousel-item v-for="item in featureVideos" :key="item.videoId">
                            <div class="video" @click="onVideo(item)">
                                <img :src="item.wholeImage" style="border-radius: 10px;overflow: hidden;"/>

                                <div class="bofang-box">
                                    <img class="bofang" :src="PIC_URL + '/experience/bofang.png'"/>
                                </div>

                            </div>
                        </el-carousel-item>
                    </el-carousel>

                </div>

                <div class="left-1-title" v-for="(item,index) in featureVideos" :key="item.videoId + 'a'" v-show="index == featureVideosIndex"
                     @click="onVideo(item)">
                    <div class="left-1-title-desc">{{ item.subject }}</div>
                    <div class="left-1-title-date">{{ item.recordStartTime | formatDate('YYYY/MM/DD') }}</div>
                </div>

                <div v-for="(item,index) in featureVideos" :key="item.videoId + 'b'" v-show="index == featureVideosIndex" @click="onVideo(item)">
                    <div class="left-1-footer" v-html="item.standpoint"></div>
                </div>

            </div>

            <!--课程预告开始 -->
            <div class="left-2" v-if="threeDayVideo">

                <div class="left-2-head">
                    <div>
                        <img :src="PIC_URL + '/experience/images/icon2.png'" style="width: 25px;height: 27px;">
                        <span class="left-2-head-text">课程预告</span>
                    </div>
                    <div class="left-2-date">{{ time | formatDate('YYYY/MM/DD') }}&nbsp;&nbsp;{{ getWeek }}</div>
                    <div class="left-2-month" @click="dialogShow = true">查看本周课表></div>
                </div>

                <div class="left-2-box">
                    <div class="left-2-box-left">昨天</div>
                    <div style="width: 283px;" v-if="threeDayVideo.yesterday && threeDayVideo.yesterday.length != 0">

                        <el-carousel direction="vertical" height="41px" indicator-position="none">
                            <el-carousel-item v-for="(val,key) in getGroup(threeDayVideo.yesterday)" :key="key + '2'">

                                <div class="left-2-box-right">
                                    <div class="left-2-box-right-p" v-for="(item,index) in val" :key="index"
                                         @click="item.isView == 1 ? onVideo(item) : openLayer('课程回放','对不起,您暂无权限观看本课程回放')">
                                        <div>
                                            <span class="date">{{ item.recordStartTime | formatDate('HH:mm') }}</span>
                                            <span class="desc">{{ item.subject }}</span>
                                        </div>
                                        <i class="iconfont icon-suozi" v-if="item.isView == 0"></i>
                                        <div class="left-2-box-right-btn">课程回放</div>
                                    </div>
                                </div>

                            </el-carousel-item>
                        </el-carousel>

                    </div>
                    <div class="left-2-box-right" v-else>暂无课程录播</div>
                </div>

                <div class="left-2-box">
                    <div class="left-2-box-left red">今天</div>
                    <div style="width: 283px;" v-if="threeDayVideo.today && threeDayVideo.today.length != 0">

                        <el-carousel direction="vertical" height="41px" indicator-position="none">
                            <el-carousel-item v-for="(val,key) in getGroup(threeDayVideo.today)" :key="key + '2'">

                                <div class="left-2-box-right">
                                    <div class="left-2-box-right-p" v-for="(item,index) in val" :key="index"
                                         @click="item.type == 1?(item.timetable.isView==1?onLive(item.timetable):openLayer('视频直播','对不起,本课堂仅对高阶版本用户开放,请升级您的权限')):(item.recordedVideo.isView==1?onVideo(item.recordedVideo):openLayer('课程回放','对不起,您暂无权限观看本课程回放'));">
                                        <div v-if="item.type == 2">
                                            <span class="date">{{ item.recordedVideo.recordStartTime | formatDate('HH:mm') }}</span>
                                            <span class="desc">{{ item.recordedVideo.subject }}</span>
                                        </div>
                                        <div v-if="item.type == 1">
                                            <span class="date">{{ item.timetable.beginTime | formatDate('HH:mm') }}</span>
                                            <span class="desc">{{ item.timetable.title }}</span>
                                        </div>
                                        <i class="iconfont icon-suozi" v-if="item.recordedVideo && item.recordedVideo.isView == 0"></i>
                                        <i class="iconfont icon-suozi" v-if="item.timetable && item.timetable.isView == 0"></i>
                                        <div class="left-2-box-right-btn">{{ item.type == 1 ? '进入课堂' : '视频回放' }}</div>
                                    </div>
                                </div>

                            </el-carousel-item>
                        </el-carousel>

                    </div>

                    <div class="left-2-box-right" v-else>暂无课程直播</div>
                </div>

                <div class="left-2-box">
                    <div class="left-2-box-left blue">明天</div>
                    <div style="width: 283px;" v-if="threeDayVideo.tomorrow && threeDayVideo.tomorrow.length != 0">

                        <el-carousel direction="vertical" height="41px" indicator-position="none">
                            <el-carousel-item v-for="(val,key) in getGroup(threeDayVideo.tomorrow)" :key="key + '2'">

                                <div class="left-2-box-right">
                                    <div class="left-2-box-right-p" v-for="(item,index) in val">
                                        <div>
                                            <span class="date">{{ item.beginTime | formatDate('HH:mm') }}</span>
                                            <span class="desc">{{ item.title }}</span>
                                        </div>
                                        <i class="iconfont icon-suozi" v-if="item.isView == 0"></i>
                                        <div class="left-2-box-right-btn">敬请期待</div>
                                    </div>
                                </div>


                            </el-carousel-item>
                        </el-carousel>

                    </div>
                    <div class="left-2-box-right" v-else>暂无课程安排</div>
                </div>

                <p class="left-2-more" @click="onVideoList(productId,centralToken)">更多往期课程>></p>

            </div>
            <!--课程预告结束-->
        </div>


        <!--本周课表开始-->
        <transition name="fade">
            <div class="dia-container" v-show="dialogShow">
                <div class="head">
                    <div v-if="weekData">{{ weekData.list[0].dateStr | formatDate('MM月DD日') }}-{{ weekData.list[6].dateStr | formatDate('MM月DD日') }}</div>
                    <div @click="dialogShow = false">
                        <i class="el-icon-arrow-down"></i>
                        <span class="up">收起</span>
                    </div>
                </div>
                <div class="dialog-content" v-if="weekData">
                    <div class="box" v-for="(item,index) in weekData.list">
                        <div class="content-left">
                            <p class="title">{{ item.dateStr | weekMsg }}</p>
                            <p>{{ item.dateStr | formatDate('MM月DD日') }}</p>
                        </div>
                        <div v-if="item.timetableList.length != 0">
                            <p v-for="val in item.timetableList" class="text">{{ val.beginTime | formatDate('HH:mm') }} {{ val.title }}</p>
                        </div>
                        <div class="empty" v-if="item.timetableList.length == 0">暂无课程安排</div>
                    </div>
                </div>

            </div>
        </transition>
        <div class="mask" v-show="dialogShow"></div>
        <!--本周课表开始-->


    </div>
</template>

<script>

import mixin from "../utils/mixin";
import {systemTime} from "../api/api";
import dayjs from "dayjs";
import {getDay, parseISO} from "date-fns";

export default {
    name: "Header",
    mixins: [mixin],
    props: {
        bannerArr: {  //广告
            type: Array,
            default: () => []
        },
        threeDayVideo: {  //课程预告
            type: Object,
            default: function () {
                return {}
            }
        },
        recentUpdate: {  //最新更新
            type: Array,
            default: () => {
            }
        },
        zfyObj: {  //战法营
            type: Object,
            default: function () {
                return null
            }
        },
        featureVideos: {  //精选视频
            type: Array,
            default: () => []
        },
        productId: {      //产品ID
            type: String,
            default: ''
        },
        bixue: {
            type: String,
            default: '/experience/images/bixue2.png'
        },
        weekData: {  //星期数据
            type: Object,
            default: () => null
        }
    },
    data() {
        return {
            featureVideosIndex: '0',     //精选视频 索引
            time: new Date().getTime(),  //系统时间
            dialogShow: false,
            centralToken: '',
        }
    },
    computed: {
        getWeek() {
            let week = dayjs(this.time).day();
            let msg = {0: '星期日', 1: '星期一', 2: '星期二', 3: '星期三', 4: '星期四', 5: '星期五', 6: '星期六'}[week];
            return msg;
        }
    },
    filters: {
        weekMsg(date) {
            let week = getDay(parseISO(date));
            let msg = {0: '星期日', 1: '星期一', 2: '星期二', 3: '星期三', 4: '星期四', 5: '星期五', 6: '星期六'}[week];
            return msg;
        }
    },
    mounted() {
        this.centralToken = this.$route.query.token || '';
        this.getSystemTime();
    },
    methods: {
        //系统时间
        async getSystemTime() {
            await systemTime().then(res => {
                this.time = res.data;
            })
        },
        //图片切换
        onChange(index) {
            this.featureVideosIndex = index;
        },
        //走马灯每两条显示数据
        getGroup(arr) {
            if (arr.length == 0) return [];

            let result = [];
            for (var i = 0; i < arr.length; i += 2) {
                result.push(arr.slice(i, i + 2));
            }
            return result;
        }
    }
}
</script>

<style scoped lang="scss">
@import "../style/style";

.mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000000;
    opacity: 0.7;
    z-index: 2000;
}

.icon-suozi {
    position: relative;
    top: 1px;
    color: #9E9E9E;
    font-size: 14px;
}

.dia-container {
    position: absolute;
    right: 10px;
    top: 370px;
    width: 330px;
    height: 543px;
    overflow: hidden;
    background-color: #FFFFFF;
    z-index: 2001;
    overflow-x: hidden;

    .head {
        width: 308px;
        height: 34px;
        padding: 0 10px;
        background: #BB100F;
        font-size: 15px;
        color: #FFFFFF;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-left: 2px solid #FF3F3E;
        font-size: 15px;

        .el-icon-arrow-down {
            font-size: 14px;
            position: relative;
            top: 1px;
        }

        .up {
            font-size: 14px;
        }

        .up:hover {
            text-decoration: underline;
        }
    }

    .dialog-content {
        display: flex;
        flex-direction: column;
        align-items: center;
        height: 509px !important;
        overflow-y: scroll;

        .box {
            width: 320px;
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            font-size: 14px;
            color: #4D4D4D;
            padding: 16px 0 16px 10px;
            border-bottom: 1px solid #FFE9E9;
            background: url($PIC_URL + '/experience/week-bg.png') no-repeat;
            background-position: bottom left;
        }

        .content-left {
            margin-right: 18px;
            text-align: center;

            .title {
                color: #333333;
                font-size: 18px;
                font-weight: bold;
                margin-bottom: 12px;
            }
        }

        .text {
            width: 230px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            -o-text-overflow: ellipsis;
        }

        .text ~ .text {
            margin-top: 9px;
        }

        .empty {
            color: #999999;
        }

    }


}

</style>

<style>
.fade-enter-active, .fade-leave-active {
    transition: opacity .25s;
    animation: dialog-fade-in 500ms ease-in;
}

.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */
{
    opacity: 0;
    animation: dialog-fade-out 500ms ease-out;
}


.el-dialog__header {
    padding: 0;
}

.el-dialog__body {
    padding: 0;
}

.dialog-month {
    position: relative;
    left: 335px;
}

@keyframes dialog-fade-in {
    0% {
        opacity: 0;
        transform: scale(1.5);
        -webkit-transform: scale(1.5);
        -ms-transform: scale(1.5);
        -moz-transform: scale(1.5);
        -o-transform: scale(1.5);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        -webkit-transform: scale(1);
        -ms-transform: scale(1);
        -moz-transform: scale(1);
        -o-transform: scale(1);
    }
}

@keyframes dialog-fade-out {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: scale(0);
        -webkit-transform: scale(0);
        -ms-transform: scale(0);
        -moz-transform: scale(0);
        -o-transform: scale(0);
        transform-origin: top right;
        /*-webkit-transform-origin: 0 0 0;
        -ms-transform-origin: 0 0 0;
        -moz-transform-origin: 0 0 0;
        -o-transform-origin: 0 0 0;*/
    }
}
</style>